package sort.yht;

import sort.util.MySort;

/**
 * 功能描述：选择排序
 * @Author: yht
 * @Date: 2021/8/11 14:12
 */
public class XuanZe implements MySort {

  @Override
  public String getName() {
    return "【选择排序】";
  }

  public int[] sort(int[] a){
    int size = a.length;
    for(int i = 1 ; i <= size - 1 ; i++) {
      int max = 0;
      int index = i;
      for(int j = 0 ; j <= size - i ; j++) {
        if(a[j] > max) {
          max = a[j];
          index = j;
        }
      }
      int tmp = a[size-i];
      a[a.length-i] = max;
      a[index] = tmp;
    }
    return a;
  }

  public static void main(String[] args) {
    MySort xuan = new XuanZe();
    xuan.testAll();
  }

}
